package dfbz.Collection工具类;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test02 {
    public static void main(String[] args) {
        Student student1 = new Student("a杨幂",20);
        Student student2 = new Student("赵丽颖",18);
        Student student3 = new Student("林允儿",22);
        Student student4 = new Student("郑爽1",16);
        Student student5 = new Student("b郑爽2",20);
        ArrayList<Student> objects = new ArrayList<>();
        objects.add(student1);
        objects.add(student2);
        objects.add(student3);
        objects.add(student4);
        objects.add(student5);
        System.out.println(objects.toString());
        Collections.sort(objects, new Comparator<Student>() { //引入Comparator接口，使用匿名内部类compare
            @Override
            public int compare(Student o1, Student o2) {
                //o1-o2 升序
//                return o1.getAge()-o2.getAge();
                int result = o2.getAge() - o1.getAge();
                if(result==0){
                    result=o2.getName().charAt(0)-o1.getName().charAt(0);
                }
                return result;
            }
        });
        System.out.println(objects);
//        Collections.sort(objects);
    }
}
